package cn.coisini.controller.v1;

import cn.coisini.api.search.AssociateWordsControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.dto.AssociateWordsDto;
import cn.coisini.model.dto.UserSearchDto;
import cn.coisini.service.AssociateWordsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 搜索联想词控制器
 */
@RestController
@RequiredArgsConstructor
public class AssociateWordsController implements AssociateWordsControllerApi {

    private final AssociateWordsService associateWordsService;

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索联想词管理", businessType = BusinessType.SELECT)
    public Result<List<AssociateWordsDto>> getAssociateWords(UserSearchDto userSearchDto) {
        return associateWordsService.getAssociateWords(userSearchDto);
    }

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索联想词管理", businessType = BusinessType.INSERT)
    public void addAssociateWords(AssociateWordsDto associateWordsDto) {
        associateWordsService.addAssociateWords(associateWordsDto);
    }

    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "搜索联想词管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> delAssociateWords(AssociateWordsDto associateWordsDto) {
        return associateWordsService.delAssociateWords(associateWordsDto);
    }
}
